home *** CD-ROM | disk | FTP | other *** search
- /* ungetch.c --- p 528 */
- #include <stdio.h>
- #include <conio.h>
- #include <ctype.h> /* For the macro isdigit() */
- main()
- {
- int intval = 0, c;
- char buff[81];
- /* Ask user to type in an integer */
- printf("Enter an integer followed by some other characters:");
- while ( (c= getche()) != EOF && isdigit(c) )
- intval = 10*intval + c - 48; /* 0 is ASCII 48 */
- /* Push back the first non-digit read from stdin */
- if (c != EOF) ungetch(c);
- /* Print message to user */
- printf("\nInteger you entered = %d.\n "
- "First non-integer encountered: %c\n", intval, getch());
- }